import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { User } from '@/types/user'

// 维护一个用户数据的仓库
export const useUserStore = defineStore(
  'cp-user',
  () => {
    const user = ref<User>() // 用户信息数据 空对象    user.value = undefined

    const setUser = (obj: User) => {
      user.value = obj
    }

    const delUser = () => {
      user.value = undefined
      // localStorage.removeItem
    }

    return {
      user,
      setUser,
      delUser
    }
  },
  {
    persist: true // 持久化
  }
)
